import { COS } from "../utils/cos";
import * as fs from "fs";
import * as process from "process";
import { unlinkFile } from "../utils/image_helper";
import { Inject } from "@nestjs/common";

export class UtilsService {

  @Inject()
  private readonly cos: COS;

  async uploadFile(file: Express.Multer.File, fileName: string) {
    const outputPath = `${process.cwd()}/temp/upload/${file.originalname}`;

    fs.writeFileSync(outputPath, file.buffer);
    await this.cos.uploadFile(outputPath, fileName);
    unlinkFile(outputPath);
    return fileName;
  }
}
